﻿namespace FastEasyAPI.Module;

public static class SqlSugarModule
{
    /// <summary>
    /// Sqlsugar注入
    /// </summary>
    /// <param name="Services"></param>
    public static void AddSqlSugarModule(this IServiceCollection Services)
    {
        Services.AddSingleton<ISqlSugarClient>(s =>
        {
            IConfiguration builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json", true, true).Build();

            var connection = builder["SqlConnection:Sql1"];
            SqlSugarScope db = new(new ConnectionConfig()
            {
                DbType = SqlSugar.DbType.SqlServer,
                ConnectionString = connection,
                IsAutoCloseConnection = true,
            });
            //db.DbFirst.IsCreateAttribute().CreateClassFile(@"A:\FastEasy\API\FastEasy.Model\Models\", "FastEasy.Model.Models");
            return db;
        });
    }
}